Carry chain for simd operations

ABSTRACT

Examples of a carry chain for performing an operation on operands each including elements of a selectable size is provided. Advantageously, the carry chain adapts to elements of different sizes. The carry chain determines a mask based on a selected size of an element. The carry chain selects, based on the mask, whether to carry a partial result of an operation performed on corresponding first portions of a first operand and a second operand into a next operation. The next operation is performed on corresponding second portions of the first operand and the second operand, and, based on the selection, the partial result of the operation. The carry chain stores, in a memory, a result formed from outputs of the operation and the next operation.

RELATED APPLICATIONS

This application claims the benefit of priority of U.S. ProvisionalApplication No. 62/079,762 filed Nov. 14, 2014, the disclosure of whichis incorporated herein by reference in its entirety.

BACKGROUND

The term single instruction, multiple data (SIMD) describes computerswith multiple processing elements that perform the same operation onmultiple data elements simultaneously. Most modern CPU designs, such asARMv8, include SIMD instructions in order to improve the performance ofmultimedia use, like graphics or audio processing; SIMD instructions canalso be used to accelerate digital signal processing in wirelesscommunications systems and cryptographic applications. The data elementwidth or size can vary, depending on the application; 8-bit, 16-bit,32-bit, and 64-bit elements are commonly supported.

SUMMARY

In accordance with an example, a method for performing an operation onoperands each including elements of a selectable size is provided, whichadapts to elements of different sizes. The method includes determining amask based on a selected size of an element. The method further includesselecting, at a multiplexer, based on the mask, whether to carry apartial result of an operation performed on corresponding first portionsof a first operand and a second operand into a next operation. The nextoperation being performed on corresponding second portions of the firstoperand and the second operand, and, based on the selection, the partialresult of the operation. The method further includes storing, in amemory, a result formed from outputs of the operation and the nextoperation.

In accordance with another example, a system for performing an operationon operands each including elements of a selectable size is provided,which adapts to elements of different sizes. The system includes amemory having computer executable instructions thereupon and anarithmetic logic unit (ALU) coupled to the memory. The computerexecutable instructions when executed by the ALU causes the ALU todetermine a mask based on a selected size of an element. The ALU furthercaused to select, based on the mask, whether to carry a partial resultof an operation performed on corresponding first portions of a firstoperand and a second operand into a next operation. The next operationbeing performed on corresponding second portions of the first operandand the second operand, and, based on the selection, the partial resultof the operation. The ALU further caused to store, in the memory, aresult formed from outputs of the operation and the next operation.

In accordance with yet another example, a tangible computer-readablestorage medium having computer readable instructions stored therein forperforming an operation on operands each including elements of aselectable size is provided, which adapts to elements of differentsizes. The computer readable instructions when executed by an arithmeticlogic unit (ALU), the ALU caused to determine a mask based on a selectedsize of an element. The ALU further caused to select, based on the mask,whether to carry a partial result of an operation performed oncorresponding first portions of a first operand and a second operandinto a next operation. The next operation being performed oncorresponding second portions of the first operand and the secondoperand, and, based on the selection, the partial result of theoperation. The ALU further caused to store, in memory, a result formedfrom outputs of the operation and the next operation.

In some examples, any of the aspects above can include one or more ofthe following features.

In other examples of the method, each element includes a leastsignificant portion and the determining includes setting the maskindicating that an a priori carry-in is carried into the operationperformed on corresponding least significant portions of the firstoperand and the second operand.

Some examples of the method further include setting the a prioricarry-in to a value when the operation is any one of subtracting,inverting, and comparing.

Other examples of the method further include setting the a prioricarry-in to a first value when the operation is an absolute valueoperation on positive-signed operands and setting the a priori carry-into a second value when the operation is an absolute value operation onnegative-signed operands.

In some examples of the method, each element includes a leastsignificant portion and a next-least significant portion. The methodfurther includes carrying an a priori carry-in into the operationperformed on corresponding least significant portions of the firstoperand and the second operand, the output of the operation being acarry-out, and carrying the carry-out into the next operation performedon corresponding next-least significant portions of the first operandand the second operand.

In other examples of the method, a size of each of the first portion andthe second portion is equal to the selected size of the element. Themethod further includes carrying a first a priori carry-in into an theoperation performed on the corresponding first portions of the firstoperand and the second operand, and carrying a second a priori carry-ininto the next operation performed on the corresponding second portionsof the first operand and the second operand.

Some examples of the method further include calculating an intermediatepartial result from the corresponding first portions of the firstoperand and the second operand and determining a carry-indicator forcomputing a carry-out of the operation. The carry-indicator isindicative of whether the carry-out is generated or a carry-in from aprevious operation is propagated. The method further includesdetermining the carry-out based on the carry-indicator and the carry-infrom the previous operation and determining the partial result of theoperation from the intermediate partial result and the carry-in from theprevious operation.

Other examples of the method include determining the partial result ofthe operation by computing the partial result from the intermediatepartial result and the carry-in from the previous operation.

Some examples of the method include determining the partial result ofthe operation by selecting the partial result using the intermediatepartial result and the carry-in from the previous operation.

Some examples of the method further include determining the selectedsize of the element based on an instruction stored in the memory. Theinstruction is a construct including the operation, first operand, andsecond operand.

Other examples of the method further include modifying the mask when theinstruction is any one of lengthening, narrowing, and widening.

Some examples of the method include selecting a mask associated with asecond element different than the element when the instruction is anyone of lengthening, narrowing, and widening. The second element beingnext larger in size than the element.

In some examples of the method, the operation and the next operationeach include a round constant. These examples further include selectingwhether to carry into the next operation a first partial result and asecond partial result of the operation performed on the round constantand the corresponding first portions of the first and second operands.The next operation being performed on the corresponding second portionsof the first and the second operands, and, based on the selection, thefirst and second partial results. In these examples, carrying the secondpartial result represents carrying a two from the operation into thenext operation.

In other examples of the system, given the element includes a leastsignificant portion, the ALU is further caused to set the maskindicating that an a priori carry-in is carried into the operationperformed on corresponding least significant portions of the firstoperand and the second operand.

In some examples of the system, given the element includes a leastsignificant portion and a next-least significant portion, the ALU isfurther caused to carry an a priori carry-in into the operationperformed on corresponding least significant portions of the firstoperand and the second operand, the output of the operation being acarry-out. The ALU is still further caused to carry the carry-out intothe next operation performed on corresponding next-least significantportions of the first operand and the second operand.

In other examples of the system, the ALU is further caused to determinethe selected size of the element from the computer executableinstructions stored in the memory.

In some examples of the system, the ALU is further caused to perform thenext operation on corresponding second portions of the first operand andthe second operand, and, based on the selection, the partial result ofthe operation.

In other examples of the tangible non-transitory computer-readablestorage medium, given the element includes a least significant portion,the ALU is further caused to set the mask indicating that an a prioricarry-in is carried into the operation performed on corresponding leastsignificant portions of the first operand and the second operand.

In some examples of the tangible non-transitory computer-readablestorage medium, given the element includes a least significant portionand a next-least significant portion, the ALU is further caused to carryan a priori carry-in into the operation performed on corresponding leastsignificant portions of the first operand and the second operand, theoutput of the operation being a carry-out. The ALU is still furthercaused to carry the carry-out into the next operation performed oncorresponding next-least significant portions of the first operand andthe second operand.

In other examples of the tangible non-transitory computer-readablestorage medium, the ALU is further caused to determine the selected sizeof the element from the computer executable instructions stored in thememory.

In some examples of the tangible non-transitory computer-readablestorage medium, the ALU is further caused to perform the next operationon corresponding second portions of the first operand and the secondoperand, and, based on the selection, the partial result of theoperation.

BRIEF DESCRIPTION OF THE DRAWINGS

The foregoing and other objects, features and advantages will beapparent from the following more particular description of the examples,as illustrated in the accompanying drawings in which like referencecharacters refer to the same parts throughout the different views. Thedrawings are not necessarily to scale, emphasis instead being placedupon illustrating the principles of the examples.

FIG. 1 is a block diagram of example system with memory and anarithmetic logical unit (ALU). The ALU includes a carry chain.

FIG. 2 is a block diagram of an example of the carry chain.

FIG. 3 is a block diagram of an example of the carry chain includingadders and multiplexers.

FIG. 4 is a block diagram of an example of the carry chain adding two64-bit operands each including eight bytes.

FIG. 5 is a block diagram of an example of the carry chain adding two64-bit operands each including two 32-words. Each word includes fourbytes.

FIG. 6 is a block diagram of an example of a carry chain for handling a“carry-the-2” scenario.

FIG. 7 is a flow chart of an example process carried out by an exampleof the carry chain.

FIG. 8 is a block diagram of an example of a pipelined carry chain.

DETAILED DESCRIPTION

FIG. 1 shows an example system 100. The system 100 includes memory 105and an arithmetic logic unit (ALU) 100. Datapaths 115 a and 115 bconnect the memory 105 and the ALU 110 together. Other examples of thesystem 100 include other numbers of datapaths including one. Memory 105stores instructions. An instruction 120 is a construct including, amongother things, an operation 125, a first operand 130, and a secondoperand 135 each provided within a field of the instruction 120. Someinstructions include fewer operands (e.g., one) or more operands (e.g.,three).

The ALU 110 reads the instruction 120 from memory 105. The instruction120 is provided to the ALU 110 over the datapath 115 a. The ALU 110performs the operation 125 on the first and second operands 130, 135,and outputs a result 140. The ALU writes the result 140 to memory 105 ata memory location specified in the instruction 120. The result 140 isprovided from the ALU over the datapath 115 b. Some examples of thesystem 100 include a memory for results separate from a memory forinstruction.

Instructions for the ALU 110 can perform adds and subtracts, and relatedoperations like compare, complement, absolute value, etc. For example,the ARM v8 SIMD instructions can perform adds and subtracts for fourdifferent element sizes—8-bit (also known as a byte), 16-bit (also knownas a half-word), 32-bit (also known as a single word or word), and64-bit (also known as a double word)—on two different datapath widths,64-bit or 128-bit. The ALU 110 can see at one time, for example, aninstruction that perform sixteen 8-bit additions, and at another time,four 32-bit additions.

To handle such a situation, one possible implementation of the ALU 110involves building a different adder for each of the different elementsizes, and then selecting among them the different adders to perform theoperation. The drawback to this approach is that the area required onthe ALU 110 to implement the solution increases with the number ofdifferent element sizes. Compared to processing a single element size,processing, for example, the four different element sizes of the ARM v8SIMD instructions requires four times the area. Considering the trendtoward smaller sized ALU's, using more processor area is undesirable. Toaddress the foregoing shortcoming and other needs, ALU 110 includes acarry chain 150 that adapts to support different element sizes.

FIG. 2 shows an example of the carry chain 150. With reference to FIG.1, the carry chain 150 performs the operation 125 on the first operand130 and the second operand 135. The first and second operands 130,135include a number of elements that are a selected size, e.g., 8, 16, 32or 64-bits. The carry chain 150 includes a series of adders of which twoare shown, adder[0] 155 a and adder[1] 155 b.

Each adder in the carry chain 150 works on part of the element called a“portion” and performs a “slice” of the operation. In FIG. 2, inslice[0], adder[0] 155 a adds a first portion 160 a of the first operand130 and a first portion 165 a of the second operand 135 together. Thefirst portions 160 a and 165 a are “corresponding portions” of the firstand second operands 130, 135. The carry chain 150 outputs a result[0]140 a. The carry chain 150 writes (stores) the output of each adder, ofwhich result[0] 140 a and result[1] 140 b are shown, in memory 105.Collectively, the stored results represent the result 140 of theoperation 130.

In slice[0], the carry chain 150 “carries” part of result[0] 140 a,called a “carry-out” from slice[0] (a prior slice of the operation) intoslice[1] (a next slice of the operation). The next adder in the carrychain 150, adder[1] 155 b, performs the next slice of the operation.Adder[0] 155 b adds together corresponding second portions 160 b,165 bof the first and second operands 130,135 and the carry-out fromslice[0], referred to as a “carry-in.” This is shown in the figure ascarry-out/carry-in 170.

The carry chain 150 continues carrying the carry-out from one slice ofthe operation into the next and processing each portion of the element.When the carry chain reaches a first portion of a next element, thecarry chain stops carrying the carry-out from the prior slice of theoperation and the carry chain restarts (described later in greaterdetail).

The carry chain 150 is set to stop carrying after performing N slices ofoperations on N number of portions of an element. For example, the carrychain 150 can be set to stop carrying after performing one slice of theoperation on one portion of the element; two slices of the operation ontwo portions of the element; four slices of the operation on fourportions of the element; and eight slices of the operation on eightportions of the element. Setting where in a carry chain to stop carryinga carry-out into a next operation and insert a carry-in is beneficialbecause it enables examples of the carry chain 150 to adapt to elementsof different sizes.

FIG. 3 shows a convenient example of the carry chain. The carry chainincludes adders and multiplexers of which three adders and twomultiplexers are shown. The adders and multiplexers are arranged withone multiplexer between two adders. Inputs to a multiplexer include acarry-out, an a priori carry-in, and a selector. As discussed above, thecarry-out is part of a result computed in a previous slice of theoperation. The value of the a priori carry-in provided to the carrychain can be computed in accordance with any number of well-knowntechniques. In a convenient example of the carry chain, in general, thevalue of the a priori carry-in is one for subtracting, comparing, andinverting operations; one or zero for absolute value operationsdepending on the sign of the operands; and zero for other operations,such as adding (described below in greater detail below). The foregoingis only an example set of operations to which examples of the carrychain can be applied. The principles of the carry chain described inthis disclosure can be applied to other operations, such ascomplementing and negating, and instructions that return the sum of twoinput operands, divided-by-2, with rounding.

The multiplexer selects whether the carry chain carries the carry-out orthe a priori carry-in into a next slice of the operation based on theselector. In a convenient example, the selectors for the multiplexersform a bit mask 175. Each bit in the mask 175 corresponds to the carrychain 150 performing a slice of the operation on a portion of theelement. It should be readily apparent to those skilled in the art thata different number of bits (e.g., two or three) can be used to index orreference the slice of the operation performed by the carry chain 150.

An element includes a least significant portion and, depending on thesize of the element, one or more next-least significant portions. Forexample, given an 8-bit portion, a 32-bit element includes one leastsignificant portion and three next-least significant portions. In theexample shown, corresponding least significant portions of the operandsare referenced, collectively, as 162 and corresponding next-leastsignificant portions of the operands are referenced, collectively, as164.

The mask 175 includes mask bit 175 a corresponding to a slice of theoperation performed on the corresponding next-least significant portions164. The mask bit 175 a is set to 0 and the multiplexer selects acarry-out CO[0] from a previous slice of the operation, slice[0]. Thiscauses the carry chain 150 to carry CO[0] into a next slice of theoperation slice[1], which is shown in the figure as “CI[1]=CO[0].” Theadder adds together CI[1] and the corresponding next-least significantportions 164.

Continuing with the example shown in FIG. 3, mask bit 175 b correspondsto a slice of the operation performed on the corresponding leastsignificant portion 162. The mask bit 175 b is set to 1 and themultiplexer selects a priori carry-in[1]. This causes the carry chain tostop carrying a carry-out and insert an a priori carry-in instead, shownin the figure as “CI[2]=a priori carry-in[1].” The adder adds together apriori carry-in[1] and the corresponding least significant portions 162.

FIG. 4 shows an example of the carry chain performing an operationadding two 64-bit operands, referred to in the figure as operand[0] andoperand[1]. Each operand includes eight elements that are each eightbits in size. Each element includes one 8-bit portion, referred to inthe figure as byte[0] through byte[7]. The size of the element and sizeof the portion are the same. Each element includes a least significantportion and no next-least significant portion. The carry chain completesthe adding operation in eight slices, referred to in the figure asslice[0] through slice[7].

In this example, a mask includes eight bits, referred to in the figureas mask[0] through mask[7]. Mask[0] through mask[7] correspond to theeight slices of the operation. Each bit in the mask is set to 1indicating that the carry chain carries an a priori carry-in into aslice of the operation. Each a priori carry-in, referred to in thefigure as, a priori CI[0] through a priori CI[7], has a value of one.

In slice[0], adder[0] adds together a priori CI[0], byte[0] ofoperand[0], and byte[0] of operand[1]. The carry chain stores theoutput, referenced in the figure as result[0], in memory (e.g., memory105 of FIG. 1). Part of result[0] is carry-out CO[0]. In slice[1],mask[1] is set to 1 and multiplexer selects a priori CI[1] over CO[0] ascarry-in CI[1]. Adder[1] adds CI[1], byte[1] of operand[1], and byte[1]of operand[2] together. The carry chain stores the output, result[1], inmemory.

The adding operation continues with the carry chain, based on the mask,carrying an a priori carry-in into a next slice of the operation insteadof a carry-out from a previous slice of the operation; adding the apriori carry-in to corresponding next bytes of operand[0] and operand[2]together; and storing the results in memory. Collectively, result[0]through result[7] form the result of the adding operation.

FIG. 5 shows an example of the carry chain performing an operationadding two 64-bit operands, referred to in the figure as operand[0] andoperand[1]. Each operand includes two elements, referred to in thefigure as (single) word[0] and (single) word[1] that are each thirty-twobits in size. Each word includes four 8-bit portions, referred to in thefigure as byte[0].word[0] through byte[3].word[0] and byte[0].word[1]through byte[3].word[1]. Byte[0] is the least significant byte of theword. Byte[1], byte[2], and byte[3] are next-least significant bytes.The carry chain completes the adding operation in eight slices, referredto in the figure as slice[0] through slice[7].

In this example, a mask includes eight bits, referred to in the figureas mask[0] through mask[7], corresponding to the eight slices of theoperation. Mask[0] corresponds with the carry chain performing slice[0]of the operation on byte[0], which is the least significant portion ofword[0]. Mask[4] corresponds with the carry chain performing slice[4] ofthe operation on byte[4], which is the least significant portion ofword[1]. Mask[0] and mask[4] are set to 1 to indicate that the carrychain carries a priori carry-in CI[0] into slice[0] and a prioricarry-in CI[0] into slice[4]. Mask[1], mask[2], mask[3], mask[5],mask[6], and mask[7] are each set to 0. This indicates that the carrychain carries a carry-out into slice[1], slice[2], slice[3], slice[5],slice[6], and slice[7].

In slice[0], the carry chain adds together a priori CI[0] andcorresponding byte[0].word[0] of operand[0] and operand[1]. The carrychain stores the output, referenced in the figure as result[0], inmemory (e.g., memory 105 of FIG. 1). Part of result[0] is carry-outCO[0].

In slice[1], mask[1] is set to 0 and the multiplexer selects CO[0] fromslice[0] over a priori CI[1] as carry-in CI[1]. The adder adds togetherCI[1] and corresponding byte[1].word[0] of operand[0] and operand[1].The carry chain stores the output, result[1], in memory. Part ofresult[1] is carry-out CO[1].

In slice[2], mask[2] is set to 0 and the multiplexer selects CO[1] fromslice[1] over a priori CI[2] as carry-in CI[2]. The adder adds togetherCI[2] and corresponding byte[2].word[0] of operand[0] and operand[1].The carry chain stores the output, result[2], in memory. Part ofresult[2] is carry-out CO[2].

In slice[3], mask[3] is set to 0 and multiplexer selects CO[2] fromslice[2] over a priori CI[3] as carry-in CI[3]. The adder adds togetherCI[3] and corresponding byte[2].word[0] of operand[0] and operand[1].The carry chain stores the output, result[3], in memory. Part ofresult[3] is carry-out CO[3].

In slice[4], mask[4] is set to 1 and multiplexer selects a priori CI[4]over CO[3] as carry-in CI[4]. The adder adds together CI[4] andcorresponding byte[1].word[1] of operand[0] and operand[1]. The carrychain stores the output, result[4], in the memory. Part of result[4] iscarry-out[4].

With mask[5], mask[6], and mask[7] set to 0, the carry chain continuesand carries carry-out CO[4] into slice[5], carries carry-out CO[5] intoslice[6], and carries carry-out CO[6] into slice[7]. The carry chainstores the outputs, result[5], result[6], and result[7], in memory.Collectively, result[0] through result[7] form the result of the addingoperation.

Some examples of the carry chain determine the selected size of theelement from an instruction stored in memory. The carry chain reads theelement size from the instruction (size field) and sets the mask. Forexample, given an element size of eight bits (byte) the carry chain setsthe mask to 11111111; given an element size of 16 bits (half-word) thecarry chain sets the mask to 01010101; and given an element size of 32bits (single word) the carry chain sets the mask to 00010001.

Other examples of the carry chain modify the mask based on aninstruction. In a convenient sample, when the carry chain processes alengthening, widening or narrowing instruction, the carry chain sees theelement size as one size larger than the element size described in thesize field of the instruction. For example, the carry chain receives alengthening instruction with an operation to add two operands eachhaving eight bytes. The carry chain sets the mask to 01010101, the maskfor a half-word, which is the next larger element than a byte.Advantageously, this approach enables the carry chain to adapt to avariety of different types of instructions.

Some instructions cause a “carry-the-2” scenario. These instructionsperform an add (or subtract), round out of the lower half of eachresult, and return only the upper half of each result. The outputelement size is one-half the input element size. For these instructions,there may already be a carry-out (first partial result) of the lowerhalf of the result and rounding can create another carry-out (secondpartial result). This has the effect of carrying a ‘2’ out of the lowerhalf-element and into the upper half-element. The fact that a ‘2’ hasbeen carried into an element means that a ‘2’ can be carried out of anyportion (e.g., byte) within the element, even though rounding is notactive for those portions.

FIG. 6 shows an example carry chain 200 for handling an operationinvolving “carry-the-2.” The carry chain 200 includes adders andmultiplexers of which adders, adder[N−1] and adder[N], and multiplexers,MUX-A and MUX-B, are shown. The adders and multiplexers are arrangedwith two multiplexers between every two adders. Describing adder[N] ingreater detail (recognizing that the following description applies toadder[N−1] and the other adders in the carry chain 200) inputs toadder[N] include portion[N] of a first operand, portion[N] of a secondoperand, and round constant[N]. Adder[N] also receives carry-in signalscin[N] and c2in[N]. The c2in signal represents carrying a two fromadder[N−1] to adder[N], which is described below in greater detail.

Adder[N] performs a slice of the operation on corresponding portions[N]of the first and second operands, round constant[N], and the signalscin[N] and c2in[N]. Adder[N] outputs the result of the operation asresult[N]. Adder[N] sends carry-out signals, cout[N] and c2out[N]. Thesignals cout[N] and c2out[N] represent, respectively, first and secondparts of result[N], i.e., first partial result and second partialresult.

The inputs to MUX-A include an a priori carry-in (a priori CI[N]),cout[N] signal, and a selector (mask[N]). The inputs to MUX-B includezero, c2out[N] signal, and the selector (mask[N]). The output of MUX-Ais the cin[N] signal and the output of MUX-B is the c2in[N] signal. Thevalues of cin[N] and c2in[N] depend on the value of mask[N]. Forexample, when mask[N] is set to zero, the multiplexer sets (selects) thevalues of cin[N] and c2in[N] to the values of cout[N−1] and c2out[N−1],respectively. In this example, a selector value of zero indicates thatthe carry chain carries cout[N−1] and c2out[N−1] from adder[N−1] toadder[N]. It should be readily apparent to those skilled in the art thatsuch a carry-out indication can be associated with a selector having adifferent value, such as one.

With continued reference to FIG. 6, consider the following example,which for ease of discussion is described using decimal math. Adder[N−1]and adder[N] are each 8-bit adders. The carry chain 200 completes theoperation in N slices, of which slice[N−1] and slice[N] are shown. Inslice[N−1], the corresponding[N−1] portions of the first and secondoperands both have a value of 192. Round constant[N−1] has a value of128. The round constant value depends on the size of an element and onthe slice of the operation being performed. In some instances, the valueof a round constant is zero. The round constant value per given slicecan be determined using any number of well-known techniques.

Adder[N−1] performs slice[N−1] of the operation. The basic sum of thecorresponding portions[N] is 384, which can be written in shorthandnotation as 1*256+128. Because adder[N−1] outputs an 8-bit number, in adifferent example, the carry chain 200 carries a “1” out of adder[N−1]and into adder[N]. This is represented as 1*256 in the notation above.In the present example, however, adder[N−1] still needs to add roundconstant[N−1], so the carry chain 200 does not carry the 1, which isshown in the figure as cout[N−1]=0.

Adder[N−1] adds round constant[N−1] (128) to the sum of thecorresponding [N−1] portions (384). The basic sum of adding 128 and 384is 512, which can be written in shorthand notation as 2*256. Becauseadder[N−1] outputs an 8-bit number, the carry chain 200 carries a “2”out of adder[N−1] and into adder[N]. This is represented as 2*256 in thenotation above. The outputs of adder[N−1] include result[N−1]=0,cout[N−1]=0, and c2out[N−1]=1. In this example, c2out[N−1]=1 representscarrying out a two.

Mask[N] is set to zero indicating that the carry chain 200 carriescout[N−1] and c2out[N−1] out from adder[N−1] and into adder[N]. Mask[N]with a value of zero 0 selects cout[N−1] and c2out[N−1]. In turn , MUX-Apasses cin[N]=0 and MUX-B passes c2in[N]=1 to adder[N]. In this example,c2in[N]=1 represents carrying in the two.

In slice[N], the corresponding [N] portions of the first and secondoperands, and round constant [N] have a value of 0. Adder[N] receivescin[N]=0 and cin[N]=1. Adder[N] performs slice[N] of the operation onthese inputs and outputs result[N]=2. The foregoing demonstrates afeature of the carry chain 200. Suppose the initial size of an elementis sixteen bits and an operation returns an 8-bit result (e.g., as in anarrowing instruction). There are no bits set in the upper eight bits ofthe 16-bit element. The carry chain 200 effectively carries a 2 out ofthe lower eight bits into the upper eight bits.

In the example described above, the carry chain 200 carries the 2 wherethe round constant is applied. Other examples of the carry chain 200carry a 2 where the round constant is not applied. In these examples,because the carry chain 200 can carry a 2 out of any one of a number ofoperation slices, the carry chain 200 is advantageously configured tocarry the 2 into any of the operation slices.

FIG. 7 shows an example process 300 performed by an example of the carrychain 150. The process 300 starts 305. The process 300 determines (310)a mask based on a selected size of an element. The process 300 selects(315), based on the mask, whether to carry a partial result of anoperation performed on corresponding first portions of a first operandand a second operand into a next operation. The next operation isperformed on corresponding second portions of the first operand and thesecond operand, and, based on the selection, the partial result of theoperation. The process 300 stores (320), in a memory (e.g., memory 105for FIG. 1), a result formed from outputs of the operation and the nextoperation. The process 300 ends (325).

FIG. 8 shows an example of a pipelined carry chain 800. The pipelinedcarry chain 800 includes adders and multiplexers of which two adders802,804 and two multiplexers 806, 808 are shown. The adders andmultiplexers are arranged with one multiplexer between two adders. Thepipelined carry chain 800 further includes logic for pipelining, whichmakes the pipelined carry chain 800 faster than other implementations ofa carry chain, such as the carry chain 150 described above withreference to FIG. 3.

An operation is performed on operand-1 810 and operand-2 812, of whichslice 1 and slice 2 of the operation are shown. In the example shown,each operand is divided into a first portion and a second portion,which, as described above, can correspond with least and next leastsignificant portions of an operand. In slice 1 of the operation, theadder 802 calculates an intermediate partial result 818 based oncorresponding first portions of operand-1 and operand-2, labeled 814 aand 814 b, respectively. The result is considered an intermediate resultbecause at this point the pipelined carry chain 800, a carry-in from aprevious slice of the operation is not considered.

The adder 802 also determines a carry-indicator 820 based on thecorresponding first portions of operand-1 and operand-2 814 a, 814 b.The carry-indicator 820 is used to calculate a carry-out of slice 1 ofthe operation, labeled in the FIG.8 as CO[1]. The carry-indicator 820 isindicative of whether the carry-out CO[1] will be generated in slice 1of the operation or will be propagated from a carry-in from a previousslice of the operation, labeled in the FIG.8 as CI[1]. Any one of anumber of well-known techniques can be used to determine carry-indicator820. In a convenient example, the intermediate partial result 818 andthe carry-indicator 820 are stored in a pipeline register or othertemporary memory.

The logic implemented by pipelined carry chain 800 includes, for eachslice of the operation, logic for determining a carry-out and a partialresult of the slice of the operation. For ease of reference and forpurposes of explaining examples of the pipelined carry chain 800, thelogic is shown in the example of FIG. 8 as determination block-A anddetermination block-B. In slice 1 of the operation, a determinationblock-A 822 determines the carry-out CO[1] based on the carry-indicator820 and the carry-in CI[1] from the previous operation.

A determination block-B 824 determines a partial result 826 of slice 1of the operation from the intermediate partial result 818 and thecarry-in CI[1] from the previous operation. In one example, thepipelined carry chain 800 computes the partial result 826 from theintermediate partial result 818 and the carry-in CI[1] 820. For ease ofdiscussion, this approach is called the “simple-adder” approach. Inanother example, the pipelined carry chain 800 selects one of severalpossible partial results as the partial result 826 using the carry-inCI[1]. For ease of discussion, this approach is called the“carry-select” approach.

The choice of a particular approach may be dictated by the area on achip needed to implement the approach, the power used in carrying outthe approach, the time needed to perform the approach, and otherconstraints. For example, the “simple-adder” approach calculates (and insome examples, stores in a pipelined carry chain) one intermediatepartial result. As such, the simple-adder approach can require less areaand consume less power than other approaches, such as the “carry-select”approach. The simple-adder approach can incur, for example, a delay ofan “8-bit ripple” and, as such, can be slower than other approaches,such as the “carry-select” approach.

One example of the “carry-select” approach requires a mux using carry-ininformation as a select and, as such, can be faster than otherapproaches, such as the “simple-adder” approach. The “carry-select”approach calculates (and in some examples, stores in a pipelined carrychain) multiple potential (possible) intermediate partial results and,as such, can require more area and can consume more power than otherapproaches, such as the “simple-adder” approach.

The several possible partial results can be readily computed from theintermediate partial result 818 according to any one of number ofwell-known techniques. These results are consider possible resultsbecause they are not determined using the carry-in CI[1].

The carry-out CO[1] from slice 1 of an operation, as determined, by theforegoing logic is then provided to the multiplexer 806 as an input.Other inputs to the multiplexer 806 include an a priori carry-in CI[1],and a selector mask[1]. The multiplexer 806 selects whether thepipelined carry chain 800 carries the carry-out CO[1] or the a prioricarry-in CI[1] into slice 2 of the operation (labeled in the FIG. 3 asCI[2]) based on the selector mask[1]. In a convenient example, theselectors for the multiplexers form a bit mask (similar to the mask 175described above with reference FIG. 3). The pipelined carry chain 800proceeds to the next slice of the operation, slice 2, and the foregoingprocess repeats with corresponding second portions of the operand 1 andoperand 2, labeled 816 a and 816 b in FIG. 8, respectively.

The foregoing examples of a pipelined approach allow a carry-in to anext slice of an operation to be calculated in what is essentially onelevel of logic instead of having to “ripple” across 8-bits of an adder,as is case with the carry chain 150 described above with reference toFIG. 3. Advantageously, the pipelined carry chain 800 is faster thanother implementations of a carry chain, such as the carry chain 150described above with reference to FIG. 3. Those skilled in the art willreadily recognize that the described pipelining technique can also beapplied to an operation involving “carry-the-2,” which was discussedabove with reference to FIG. 6.

The above-described systems and methods can be implemented in digitalelectronic circuitry, in computer hardware, firmware, and/or software.The implementation can be as a computer program product. Theimplementation can, for example, be in a machine-readable storagedevice, for execution by, or to control the operation of, dataprocessing apparatus. The implementation can, for example, be aprogrammable processor, a computer, and/or multiple computers.

A computer program can be written in any form of programming language,including compiled and/or interpreted languages, and the computerprogram can be deployed in any form, including as a stand-alone programor as a subroutine, element, and/or other unit suitable for use in acomputing environment. A computer program can be deployed to be executedon one computer or on multiple computers at one site.

Method steps can be performed by one or more programmable processorsexecuting a computer program to perform functions of the invention byoperating on input data and generating output. Method steps can also beperformed by and an apparatus can be implemented as special purposelogic circuitry. The circuitry can, for example, be a FPGA (fieldprogrammable gate array) and/or an ASIC (application-specific integratedcircuit). Subroutines and software agents can refer to portions of thecomputer program, the processor, the special circuitry, software, and/orhardware that implement that functionality.

Processors suitable for the execution of a computer program include, byway of example, both general and special purpose microprocessors, andany one or more processors of any kind of digital computer. Generally, aprocessor receives instructions and data from a read-only memory or arandom access memory or both. The essential elements of a computer are aprocessor for executing instructions and one or more memory devices forstoring instructions and data. Generally, a computer can include, can beoperatively coupled to receive data from and/or transfer data to one ormore mass storage devices for storing data (e.g., magnetic,magneto-optical disks, or optical disks).

Data transmission and instructions can also occur over a communicationsnetwork. Information carriers suitable for embodying computer programinstructions and data include all forms of non-volatile memory,including by way of example semiconductor memory devices. Theinformation carriers can, for example, be EPROM, EEPROM, flash memorydevices, magnetic disks, internal hard disks, removable disks,magneto-optical disks, CD-ROM, and/or DVD-ROM disks. The processor andthe memory can be supplemented by, and/or incorporated in specialpurpose logic circuitry.

To provide for interaction with a user, the above described techniquescan be implemented on a computer having a display device. The displaydevice can, for example, be a cathode ray tube (CRT) and/or a liquidcrystal display (LCD) monitor. The interaction with a user can, forexample, be a display of information to the user and a keyboard and apointing device (e.g., a mouse or a trackball) by which the user canprovide input to the computer (e.g., interact with a user interfaceelement). Other kinds of devices can be used to provide for interactionwith a user. Other devices can, for example, be feedback provided to theuser in any form of sensory feedback (e.g., visual feedback, auditoryfeedback, or tactile feedback). Input from the user can, for example, bereceived in any form, including acoustic, speech, and/or tactile input.

The above described techniques can be implemented in a distributedcomputing system that includes a back-end component. The back-endcomponent can, for example, be a data server, a middleware component,and/or an application server. The above described techniques can beimplemented in a distributing computing system that includes a front-endcomponent. The front-end component can, for example, be a clientcomputer having a graphical user interface, a Web browser through whicha user can interact with an example implementation, and/or othergraphical user interfaces for a transmitting device. The components ofthe system can be interconnected by any form or medium of digital datacommunication (e.g., a communication network). Examples of communicationnetworks include a local area network (LAN), a wide area network (WAN),the Internet, wired networks, and/or wireless networks.

The system can include clients and servers. A client and a server aregenerally remote from each other and typically interact through acommunication network. The relationship of client and server arises byvirtue of computer programs running on the respective computers andhaving a client-server relationship to each other.

Packet-based networks can include, for example, the Internet, a carrierinternet protocol (IP) network (e.g., local area network (LAN), widearea network (WAN), campus area network (CAN), metropolitan area network(MAN), home area network (HAN)), a private IP network, an IP privatebranch exchange (IPBX), a wireless network (e.g., radio access network(RAN), 802.11 network, 802.16 network, general packet radio service(GPRS) network, HiperLAN), and/or other packet-based networks.Circuit-based networks can include, for example, the public switchedtelephone network (PSTN), a private branch exchange (PBX), a wirelessnetwork (e.g., RAN, bluetooth, code-division multiple access (CDMA)network, time division multiple access (TDMA) network, global system formobile communications (GSM) network), and/or other circuit-basednetworks.

The transmitting device can include, for example, a computer, a computerwith a browser device, a telephone, an IP phone, a mobile device (e.g.,cellular phone, personal digital assistant (PDA) device, laptopcomputer, electronic mail device), and/or other communication devices.The browser device includes, for example, a computer (e.g., desktopcomputer, laptop computer) with a world wide web browser (e.g.,Microsoft® Internet Explorer® available from Microsoft Corporation,Mozilla® Firefox available from Mozilla Corporation). The mobilecomputing device includes, for example, a Blackberry®.

Comprise, include, and/or plural forms of each are open ended andinclude the listed parts and can include additional parts that are notlisted. And/or is open ended and includes one or more of the listedparts and combinations of the listed parts.

One skilled in the art will realize the invention may be embodied inother specific forms without departing from the spirit or essentialcharacteristics thereof. The foregoing embodiments are therefore to beconsidered in all respects illustrative rather than limiting of theinvention described herein. Scope of the invention is thus indicated bythe appended claims, rather than by the foregoing description, and allchanges that come within the meaning and range of equivalency of theclaims are therefore intended to be embraced therein.

What is claimed is:
 1. A method for performing an operation on operandseach including elements of a selectable size, the method comprising:determining a mask based on a selected size of an element; selecting, ata multiplexer, based on the mask, whether to carry a partial result ofan operation performed on corresponding first portions of a firstoperand and a second operand into a next operation, the next operationbeing performed on corresponding second portions of the first operandand the second operand, and, based on the selection, the partial resultof the operation; and storing, in a memory, a result formed from outputsof the operation and the next operation.
 2. The method of claim 1wherein the element includes a least significant portion; and whereinthe determining includes setting the mask indicating that an a prioricarry-in is carried into the operation performed on corresponding leastsignificant portions of the first operand and the second operand.
 3. Themethod of claim 2 further comprising setting the a priori carry-in to avalue when the operation is any one of subtracting, inverting, andcomparing.
 4. The method of claim 2 further comprising: setting the apriori carry-in to a first value when the operation is an absolute valueoperation on positive-signed operands; and setting the a priori carry-into a second value different than the first value when the operation isan absolute value operation on negative-signed operands.
 5. The methodof claim 1 wherein the element includes a least significant portion anda next-least significant portion; wherein the selecting furtherincludes: carrying an a priori carry-in into the operation performed oncorresponding least significant portions of the first operand and thesecond operand, the output of the operation being a carry-out; andcarrying the carry-out into the next operation performed oncorresponding next-least significant portions of the first operand andthe second operand.
 6. The method of claim 1 wherein a size of each ofthe first portion and the second portion is equal to the selected sizeof the element; and wherein the selecting includes carrying a first apriori carry-in into an the operation performed on the correspondingfirst portions of the first operand and the second operand, and carryinga second a priori carry-in into the next operation performed on thecorresponding second portions of the first operand and the secondoperand.
 7. The method of claim 1 wherein the operation and the nextoperation each include a round constant; and wherein the selectingincludes selecting whether to carry into the next operation a firstpartial result and a second partial result of the operation performed onthe round constant and the corresponding first portions of the first andsecond operands, the next operation being performed on the correspondingsecond portions of the first and the second operands, and, based on theselection, the first and second partial results; and wherein carryingthe second partial result represents carrying a two from the operationinto the next operation.
 8. The method of claim 1 further comprising,calculating an intermediate partial result from the corresponding firstportions of the first operand and the second operand; determining acarry-indicator for computing a carry-out of the operation, thecarry-indicator being indicative of whether the carry-out is generatedor a carry-in from a previous operation is propagated; determining thecarry-out based on the carry-indicator and the carry-in from theprevious operation; determining the partial result of the operation fromthe intermediate partial result and the carry-in from the previousoperation.
 9. The method of claim 8 wherein determining the partialresult of the operation includes computing the partial result from theintermediate partial result and the carry-in from the previousoperation.
 10. The method of claim 8 wherein determining the partialresult of the operation includes selecting the partial result using theintermediate partial result and the carry-in from the previousoperation.
 11. The method of claim 1 further comprising determining theselected size of the element based on an instruction stored in thememory, the instruction being a construct including the operation, firstoperand, and second operand.
 12. The method of claim 11 furthercomprising modifying the mask based on the instruction being any one oflengthening, narrowing, and widening.
 13. The method of claim 11 furthercomprising when the instruction is any one of lengthening, narrowing,and widening, selecting a mask associated with a second elementdifferent than the element, the second element being next larger in sizethan the element.
 14. The method of claim 1 further comprisingperforming the next operation on corresponding second portions of thefirst operand and the second operand, and, based on the selection, thepartial result of the operation.
 15. A system for performing anoperation on operands each including elements of a selectable size, thesystem comprising: a memory having computer executable instructionsthereupon; and an arithmetic logic unit (ALU) coupled to the memory, thecomputer executable instructions when executed by the ALU cause the ALUto: determine a mask based on a selected size of an element; select,based on the mask, whether to carry a partial result of an operationperformed on corresponding first portions of a first operand and asecond operand into a next operation, the next operation being performedon corresponding second portions of the first operand and the secondoperand, and, based on the selection, the partial result of theoperation; and store, in the memory, a result formed from outputs of theoperation and the next operation.
 16. The system of claim 15 wherein theelement includes a least significant portion and the ALU is furthercaused to set the mask indicating that an a priori carry-in is carriedinto the operation performed on corresponding least significant portionsof the first operand and the second operand.
 17. The system of claim 15wherein each element includes a least significant portion and anext-least significant portion, and the ALU is further caused to: carryan a priori carry-in into the operation performed on corresponding leastsignificant portions of the first operand and the second operand, theoutput of the operation being a carry-out; and carry the carry-out intothe next operation performed on corresponding next-least significantportions of the first operand and the second operand.
 18. The system ofclaim 15 wherein the ALU is further caused to determine the selectedsize of the element from the computer executable instructions store inthe memory.
 19. The system of claim 15 wherein the ALU is further causedto perform the next operation on corresponding second portions of thefirst operand and the second operand, and, based on the selection, thepartial result of the operation.
 20. A tangible non-transitorycomputer-readable storage medium having computer readable instructionsstored therein for performing an operation on operands each includingelements of a selectable size, which when executed by an arithmeticlogic unit (ALU), cause the ALU to: determine a mask based on a selectedsize of an element; select, based on the mask, whether to carry apartial result of an operation performed on corresponding first portionsof a first operand and a second operand into a next operation, the nextoperation being performed on corresponding second portions of the firstoperand and the second operand, and, based on the selection, the partialresult of the operation; and store, in memory, a result formed fromoutputs of the operation and the next operation.